//
//  StatusCellTopView.swift
//  weibo
//
//  Created by mac on 15/12/19.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit
import SDWebImage

class StatusCellTopView: UIView {
    //定义微博模型属性
    var status: Status? {
        didSet {
            //绑定数据
            iconImage.sd_setImageWithURL(status?.user?.headURL)
            nameLable.text = status?.user?.name
            mbrankImage.image = status?.user?.mbrankImage
            verified_type_image.image = status?.user?.verified_type_image
            contentLable.text = status?.text
            //设置配图视图的 图片的数组 数据源
            pictureView.imageURLs = status?.imageURLs
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //backgroundColor = UIColor(white: 0.9, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //自定义顶部视图
    private func setupUI() {
        //添加子视图
        addSubview(iconImage)
        addSubview(nameLable)
        addSubview(mbrankImage)
        addSubview(timeLable)
        addSubview(verified_type_image)
        addSubview(sourceLable)
        addSubview(contentLable)
        addSubview(pictureView)
        addSubview(sepView)
        //设置约束
        sepView.backgroundColor = UIColor.randomColor()
        sepView.snp_makeConstraints { (make) -> Void in
            make.left.top.right.equalTo(self)
            make.height.equalTo(10)
        }
        iconImage.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMarigin)
            make.top.equalTo(self.snp_top).offset(StatusCellMarigin)
            make.size.equalTo(CGSize(width: StatusCellHeadImageWidth, height: StatusCellHeadImageWidth))
        }
        //设置图片的圆角
        iconImage.layer.cornerRadius = 17
        //裁减
        iconImage.layer.masksToBounds = true
        nameLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImage.snp_top)
            make.left.equalTo(iconImage.snp_right).offset(StatusCellMarigin)
        }
        mbrankImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLable.snp_top)
            make.left.equalTo(nameLable.snp_right).offset(StatusCellMarigin)
        }
        verified_type_image.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImage.snp_right).offset(-7)
            make.centerY.equalTo(iconImage.snp_bottom).offset(-3)
        }
        timeLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconImage.snp_bottom)
            make.left.equalTo(iconImage.snp_right).offset(StatusCellMarigin)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLable.snp_bottom)
            make.left.equalTo(timeLable.snp_right).offset(StatusCellMarigin)
        }
        contentLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImage.snp_bottom).offset(StatusCellMarigin)
            make.left.equalTo(self.snp_left).offset(StatusCellMarigin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLable.snp_bottom).offset(StatusCellMarigin)
            make.left.equalTo(contentLable.snp_left)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        //对顶部视图的底部设置约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMarigin)
        }
        
    }
    //懒加载所有的子视图
    private lazy var sepView: UIView = UIView()
    private lazy var iconImage: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLable: UILabel = UILabel(title: "张三", color: themeColor, fontSize: 14)
    //会员等级图标
    private lazy var mbrankImage: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //认证信息图片
    private lazy var verified_type_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    private lazy var timeLable: UILabel = UILabel(title: "11:11", color: themeColor, fontSize: 10)
    private lazy var sourceLable: UILabel = UILabel(title: "隔壁老王", color: themeColor, fontSize: 10)
    private lazy var contentLable: UILabel = UILabel(title: "下雨天炸鸡和辣条更加配哦,下雨天炸鸡和辣条更加配哦下雨天炸鸡和辣条更加", color: themeColor, fontSize: 14, margin: StatusCellMarigin)
    //配图视图
    private lazy var pictureView: StatusPictureView = StatusPictureView()
}
